<template>
	<view>
		<u-cell-group>
			<u-cell-item @click='editPhone' title="更换手机号"></u-cell-item>
			<u-cell-item @click='setPassword' title="修改密码"></u-cell-item>
			<u-cell-item title="接收消息设置"></u-cell-item>
			<u-cell-item title="检查更新" value="V1.0.0"></u-cell-item>
			<u-cell-item title="清除缓存" value="100MB"></u-cell-item>
			<u-cell-item title="账号注销" @click='accountCancellation'></u-cell-item>
		</u-cell-group>
		<view class="" style="padding: 0 24rpx;">
			<u-button @click="signOut" type="primary" style="margin-top: 25rpx;width: 100%;">退出登录</u-button>

		</view>
		<u-modal title="请填写" :show-cancel-button='true' v-model="showPaw" @confirm="confirm" ref="uModal"
			:async-close="true">
			<view class="paw_box">
				<u-field type='text' :password='true' :border-bottom='false' :error-message="errorMessage"
					v-model="passwordVal" label="密码:" placeholder="请填写密码">
				</u-field>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import cacheFunc from '@/utils/cache.js'
	import {
		logOut
	} from '@/utils/logOut.js'
	export default {
		data() {
			return {
				passwordVal: '',
				showPaw: false,
				errorMessage: ''
			};
		},
		methods: {
			accountCancellation() {
				// accountCancellation	
				uni.showModal({
					title: '提示',
					content: '确认注销吗?',
					success(res) {
						if (res.confirm) {
							that.$u.api.accountCancellation().then(res => {
								logOut('注销成功,请重新登录!')
							})
						}

					}
				})
			},
			confirm() {
				if (!this.passwordVal) {
					this.errorMessage = '请输入密码'
					this.$refs.uModal.clearLoading();
					return
				}
				this.$u.api.setPassword({
					passWord: this.passwordVal
				}).then(res => {
					uni.showToast({
						title: '密码设置成功!',
						icon: 'none'
					})
					this.$refs.uModal.clearLoading();
					this.errorMessage = ''
					this.passwordVal = ''
					this.showPaw = false;
				})
			},
			// setPassword
			setPassword() {
				uni.navigateTo({
					url: '/pages/editPassword/editPassword'
				})
				// this.showPaw = true
			},
			editPhone() {
				uni.navigateTo({
					url: '/pages/editPhone/editPhone'
				})
				// this.showPaw = true
			},
			signOut() {
				this.cache.removeCache('busToken')
				this.cache.removeCache('busUserInfo')
				uni.showToast({
					title: '退出成功',
					icon: 'none'
				})
				uni.redirectTo({
					url: '/pages/login/login'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.paw_box {
		padding: 20rpx;
	}
</style>
